<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/13 0013
 * Time: 上午 10:57
 */
namespace app\api\controller;

use app\common\validate\SmsValidate;
use think\Request;

class Sms{
    public function getPhoneCode(Request $request){
        (new SmsValidate())->goCheck();
        $param = $request->param();
//        if($param['client_key'] != config('sms.client_key')){
//            return show(config('status.ERROR_STATUS'),'客户端密钥错误','客户端密钥错误');
//        }
        $conf = [
            'api_key' => config('sms.APIKEY'),
            'use_ssl' => false,
        ];
        $Sms = new \app\common\lib\Sms($conf);
        $smscode = randString();
        $result = $Sms->send($param['phone'],'验证码：'.$smscode.config('sms.sing'));
        if( $result ){
            if( isset( $result['error'] ) &&  $result['error'] == 0 ){
                return show(config('status.success_code'),'短信发送成功',$smscode);
            }else{
                return show(config('status.error_code'),'短信发送失败',$result['msg']);
            }
        }else{
            return show(config('status.error_code'),$Sms->last_error(),$Sms->last_error());
        }

    }
}